package com.breeze.components.log;

import com.breeze.components.log.converter.ClientIpPatternConverter;
import com.breeze.components.log.converter.DefaultPatternConverter;
import com.breeze.components.log.converter.HostPatternConverter;
import com.breeze.components.log.converter.PortPatternConverter;
import com.breeze.components.log.converter.UrlPatternConverter;
import org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout;

/**
 * @author breeze
 */
public class CustomPatternLogbackLayout extends TraceIdPatternLogbackLayout {

  static {
    DEFAULT_CONVERTER_MAP.put("local_host", HostPatternConverter.class.getName());
    DEFAULT_CONVERTER_MAP.put("local_port", PortPatternConverter.class.getName());
    DEFAULT_CONVERTER_MAP.put("client_ip", ClientIpPatternConverter.class.getName());
    try {
      Class.forName("org.springframework.web.context.request.RequestContextHolder");
      Class.forName("jakarta.servlet.http.HttpServletRequest");
      DEFAULT_CONVERTER_MAP.put("url", UrlPatternConverter.class.getName());
    } catch (ClassNotFoundException e) {
      DEFAULT_CONVERTER_MAP.put("url", DefaultPatternConverter.class.getName());
    }
  }
}
